<template>
  <div class="view-wrapper">
    <div class="main">
      <div class="main_title">{{title}}</div>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="130px" class="demo-ruleForm">
        <el-form-item label="是否启用：" prop="status">
          <el-switch active-text="开" inactive-text="关" v-model="ruleForm.status" active-value="1" inactive-value="2"
            :disabled='switchDisabled'>
          </el-switch>
        </el-form-item>
        <el-form-item label="活动名称：" prop="activityName">
          <el-input v-model="ruleForm.activityName" maxlength="20" placeholder="请填写活动名称" :style="{width:width+ 'px'}" :disabled='switchDisabled'>
          </el-input>
        </el-form-item>
        <el-form-item label="活动时间：" prop="date">
          <el-date-picker v-model="ruleForm.date" type="datetimerange" range-separator="至" start-placeholder="开始日期" :clearable='false'
            end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="活动规则：" required>
          <!-- 新增 -->
          <el-form-item prop="couponStock" style="margin-bottom: 30px" v-if="type != 'edit'">
            <span class="lable_title">优惠券库存：</span>
            <el-input v-model="ruleForm.couponStock" placeholder="请填写优惠券总库存数量" style="width: 316px;">
              <template slot="append">张</template>
            </el-input>
          </el-form-item>
          <!-- 编辑 -->
          <el-form-item prop="" style="margin-bottom: 30px" v-if="type == 'edit'">
            <span class="lable_title">添加优惠券库存：</span>
            <el-input v-model="ruleForm.couponStock" placeholder="请填写添加优惠券总库存数量" style="width: 316px;">
              <template slot="append">张</template>
            </el-input>
            <span class="lable_title_end">（原库存{{this.couponStock}}，剩余{{this.usableStock}})</span>
          </el-form-item>
          <el-form-item prop="mostEveryDay" style="margin-bottom: 30px">
            <span class="lable_title">每天最多领取：</span>
            <el-input v-model="ruleForm.mostEveryDay" placeholder="请填写" style="width: 316px;" :disabled='switchDisabled'>
              <template slot="append">张</template>
            </el-input>
            <span class="lable_title_end">(请填该活动每天最多领券优惠券数量)</span>
          </el-form-item>
          <el-form-item prop="mostEveryPerson" style="margin-bottom: 30px">
            <span class="lable_title">每人最多领取：</span>
            <el-input v-model="ruleForm.mostEveryPerson" placeholder="请填写" style="width: 316px;" :disabled='switchDisabled'>
              <template slot="append">张</template>
            </el-input>
            <span class="lable_title_end">(请填该活动每个用户最多领券优惠券数量)</span>
          </el-form-item>
          <el-form-item prop="mostEveryPersonDay" style="margin-bottom: 30px">
            <span class="lable_title">每人每天最多领取：</span>
            <el-input v-model="ruleForm.mostEveryPersonDay" placeholder="请填写" style="width: 316px;" :disabled='switchDisabled'>
              <template slot="append">张</template>
            </el-input>
            <span class="lable_title_end">(请填该活动每个用户每天最多领券优惠券数量)</span>
          </el-form-item>
        </el-form-item>
        <el-form-item label="优惠券名称：" prop="couponName">
          <el-input v-model="ruleForm.couponName" maxlength="20" placeholder="请填写优惠券名称" :style="{width:width+ 'px'}" :disabled='switchDisabled'>
          </el-input>
        </el-form-item>
        <el-form-item label="优惠券有效期：" required>
          <el-form-item prop="validityType" style="margin-bottom: 10px">
            <el-radio-group v-model="ruleForm.validityType" :disabled='switchDisabled'>
              <el-radio :label="'1'">长期有效</el-radio>
              <el-radio :label="'2'">相对时间生效</el-radio>
              <el-radio :label="'3'">固定时间生效</el-radio>
            </el-radio-group>
          </el-form-item>
          <div class="flex" v-if="ruleForm.validityType=='2'">
            <el-form-item prop="afterReceivingDay" style="margin-bottom: 10px">
              <span class="lable_title">领取</span>
              <el-input v-model="ruleForm.afterReceivingDay" placeholder="输入天数" style="width: 180px;" :disabled='switchDisabled'>
                <template slot="append">天</template>
              </el-input>
              <span class="lable_title_end">后生效；有效期为</span>
            </el-form-item>
            <el-form-item prop="effectiveDays" style="margin-left: 10px">
              <el-input v-model="ruleForm.effectiveDays" placeholder="输入天数" style="width: 180px;" :disabled='switchDisabled'>
                <template slot="append">天</template>
              </el-input>
            </el-form-item>
          </div>
          <div v-if="ruleForm.validityType=='3'">
            <el-form-item prop="dateTwo">
              <el-date-picker v-model="ruleForm.dateTwo" type="daterange" range-separator="至" start-placeholder="开始日期"
                end-placeholder="结束日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd" :disabled='switchDisabled' :clearable='false'>
              </el-date-picker>
            </el-form-item>
          </div>
        </el-form-item>
        <el-form-item label="使用条件：" required>
          <el-form-item prop="useConditions" style="margin-bottom: 10px">
            <el-radio-group v-model="ruleForm.useConditions" :disabled='switchDisabled'>
              <el-radio :label="'1'">平台通用</el-radio>
              <el-radio :label="'2'">指定行业</el-radio>
              <el-radio :label="'3'">指定店铺</el-radio>
              <el-radio :label="'4'">指定店铺等级</el-radio>
            </el-radio-group>
          </el-form-item>
          <div class="flex" v-if="ruleForm.useConditions=='2'">
            <el-form-item prop="shopTypeIdLs" style="margin-bottom: 10px">
              <el-cascader filterable clearable v-model="ruleForm.shopTypeIdLs" :options="typeList" style="width:400px" :disabled='switchDisabled'
                placeholder="请选择行业" :props="{ value: 'id',label: 'label',children: 'children', multiple: true,}" @change="changeShopTypeIdLs">
              </el-cascader>
            </el-form-item>
          </div>
          <div v-if="ruleForm.useConditions=='3'">
            <el-form-item prop="shopIdList">
              <el-select v-model="ruleForm.shopIdList" filterable multiple placeholder="请选择店铺" style="width:400px" :disabled='switchDisabled'>
                <el-option v-for="item in shopList" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div v-if="ruleForm.useConditions=='4'">
            <el-form-item prop="merchantCreditGradeList">
              <el-select v-model="ruleForm.merchantCreditGradeList" filterable multiple placeholder="请选择店铺等级" :disabled='switchDisabled'
                style="width:400px">
                <el-option v-for="item in gradeList" :key="item.id" :label="item.value" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
        </el-form-item>
        <el-form-item label="优惠券类型：" prop="couponType">
          <el-select v-model="ruleForm.couponType" placeholder="请选择优惠券类型" @change="couponTypeChange" :disabled='switchDisabled'>
            <el-option v-for="item in couponTypeList" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <!-- 满减券条件下 -->
        <div v-if="ruleForm.couponType=='1'">
          <el-form-item label="优惠条件：" prop="preferentialCondition">
            <el-input v-model="ruleForm.preferentialCondition" placeholder="请填写优惠条件" :style="{width:width+ 'px'}" :disabled='switchDisabled'>
              <template slot="append">元</template>
            </el-input>
            <span class="lable_title_end">(填写大于等于0且最多保留两位小数的数值)</span>
          </el-form-item>
          <el-form-item label="优惠力度：" prop="preferentialDiscount">
            <el-input v-model="ruleForm.preferentialDiscount" placeholder="请填写优惠力度" :style="{width:width+ 'px'}" :disabled='switchDisabled'>
              <template slot="append">元</template>
            </el-input>
            <span class="lable_title_end">(填写大于0且最多保留两位小数的数值)</span>
          </el-form-item>
        </div>
        <!-- 折扣券条件下 -->
        <div v-if="ruleForm.couponType=='2'">
          <el-form-item label="优惠条件：" prop="preferentialCondition">
            <el-input v-model="ruleForm.preferentialCondition" placeholder="请填写优惠条件" :style="{width:width+ 'px'}" :disabled='switchDisabled'>
              <template slot="append">元</template>
            </el-input>
            <span class="lable_title_end">(填写大于等于0且最多保留两位小数的数值)</span>
          </el-form-item>
          <el-form-item label="优惠力度：" prop="preferentialDiscount">
            <el-input v-model="ruleForm.preferentialDiscount" placeholder="请输入折扣力度" :style="{width:width+ 'px'}" :disabled='switchDisabled'>
              <template slot="append">折</template>
            </el-input>
            <span class="lable_title_end">(填写0.1-9.9之间的数值)</span>
          </el-form-item>
        </div>
        <el-form-item label="使用说明：">
          <el-input type="textarea" :rows="6" style="width: 600px" v-model="ruleForm.instructions"
            placeholder="请输入优惠券使用说明" maxlength="5000" show-word-limit>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')" v-if="type != 'edit'" :loading="submitLoading">立即创建
          </el-button>
          <el-button type="primary" @click="editForm('ruleForm')" v-if="type == 'edit' && platformType=='1'" :loading="submitLoading">保存提交
          </el-button>
          <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
          <el-button @click="clickBack">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
  import {
    adminDict,
    shopTypeList,
    shopSelectDown,
    couponInfo,
    addCoupon,
    couponEdit
  } from "@/api/couponManagement";
  export default {
    data() {
      var checkStock = (rule, value, callback) => { //优惠券库存校验
        let regNumber = /^\+?[1-9][0-9]*$/; //大于0的正整数
        if (!value) {
          return callback(new Error('请填写数量'));
        } else if (regNumber.test(value) == false) {
          return callback(new Error('请填写大于0的正整数'));
        } else {
          return callback()
        }
      };
      var checkMostEveryDay = (rule, value, callback) => { //每天最多领取校验
        console.log(value, this.ruleForm.couponStock)
        let regNumber = /^\+?[1-9][0-9]*$/; //大于0的正整数
        if (!value) {
          return callback(new Error('请填该活动每天最多领券优惠券数量'));
        } else if (regNumber.test(value) == false) {
          return callback(new Error('请填写大于0的正整数'));
        } else if (this.type != 'edit'&&(Number(value) > Number(this.ruleForm.couponStock))) {
          setTimeout(() => {
            this.ruleForm.mostEveryDay = ''
          }, 1000)
          return callback(new Error('输入值不能大于库存量'));
        } else {
          return callback()
        }
      };
      var checkMostEveryPerson = (rule, value, callback) => { //每人最多领取校验
        let regNumber = /^\+?[1-9][0-9]*$/; //大于0的正整数
        if (!value) {
          return callback(new Error('请填该活动每个用户最多领券优惠券数量'));
        } else if (regNumber.test(value) == false) {
          return callback(new Error('请填写大于0的正整数'));
        } else if (this.type != 'edit'&&(Number(value) > Number(this.ruleForm.couponStock))) {
          setTimeout(() => {
            this.ruleForm.mostEveryPerson = ''
          }, 1000)
          return callback(new Error('输入值不能大于库存量'));
        } else {
          return callback()
        }
      };
      var checkMostEveryPersonDay = (rule, value, callback) => { //每人每天最多领取
        let regNumber = /^\+?[1-9][0-9]*$/; //大于0的正整数
        if (!value) {
          return callback(new Error('请填该活动每个用户每天最多领券优惠券数量'));
        } else if (regNumber.test(value) == false) {
          return callback(new Error('请填写大于0的正整数'));
        } else if (this.type != 'edit'&&(Number(value) > Number(this.ruleForm.mostEveryDay))) {
          setTimeout(() => {
            this.ruleForm.mostEveryPersonDay = ''
          }, 1000)
          return callback(new Error('输入值不能大于每天最多领取量'));
        } else {
          return callback()
        }
      };
      var checkAfterReceivingDay = (rule, value, callback) => {
        let regNumber = /^\+?[0-9][0-9]*$/; //大于等于0的正整数
        console.log(value)
        if (value==='') {
          return callback(new Error('请填写领取后几天生效'));
        } else if (regNumber.test(value) == false) {
          return callback(new Error('请填写大于等于0的正整数'));
        } else {
          return callback()
        }
      };
      var checkEffectiveDays = (rule, value, callback) => {
        let regNumber = /^\+?[1-9][0-9]*$/; //大于0的正整数
        if (!value) {
          return callback(new Error('请填写有效天数'));
        } else if (regNumber.test(value) == false) {
          return callback(new Error('请填写大于0的正整数'));
        } else {
          return callback()
        }
      };
      var checkPreferentialCondition = (rule, value, callback) => {
        // let regNumber = /^([0-9]\d*)(\.\d{1,6})?$|^0\.\d{1,6}?$/;; //大于等于0的数值
        let regNumber = /(^[0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;//大于0等于0且保留两位小数的数值
        if (value==='') {
          return callback(new Error('请填写优惠条件'));
        } else if (regNumber.test(value) == false) {
          return callback(new Error('请填写大于等于0且保留两位小数的数值'));
        } else {
          return callback()
        }
      };
      var checkPreferentialDiscount = (rule, value, callback) => {
        // let regNumber = /^([1-9]\d*)(\.\d{1,6})?$|^0\.\d{1,6}?$/;; //大于0的数值
        let regNumber = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/; //大于0的数值且最多保留两位小数的数值
        let regex = /^((0\.[1-9]{1})|(([1-9]{1})(\.\d{1})?))$/; //折扣0.1-9.9
        if (value==='' && this.ruleForm.couponType == '1') {
          return callback(new Error('请填写优惠力度'));
        } else if (value==='' && this.ruleForm.couponType == '2') {
          return callback(new Error('请填写折扣力度'));
        } else if (this.ruleForm.couponType == '1' && (regNumber.test(value) == false || value=='0.00'|| value=='0.0')) {
          return callback(new Error('请填写大于0且最多保留两位小数的数值'));
        } else if (this.ruleForm.couponType == '2' && regex.test(value) == false) {
          return callback(new Error('填写0.1-9.9之间的数值'));
        } else {
          return callback()
        }
      };
      return {
        type: '', //
        title: '新增优惠券活动',
        width: '400',
        switchDisabled: false,
        editId: '', //编辑id
        usableStock: '', //剩余库存
        couponStock: '', //原库存
        submitLoading: false,
        typeList: [], //行业类型数组
        shopList: [], //店铺类型数组
        gradeList: [], //店铺等级数组
        couponTypeList: [], //优惠券类型数组
        ruleForm: {
          //   delivery: true,
          activityName: '', //活动名称
          activityStartTime: '', //活动开始时间
          activityEndTime: '', //活动结束时间
          date: [], //活动时间，表单校验用
          couponStock: '', //优惠券库存
          mostEveryDay: '', //每天最多领取
          mostEveryPerson: '', //每人最多领取
          mostEveryPersonDay: '', //每人每天最多领取
          couponName: '', //优惠券名称
          validityType: '1', //有效期类型;(1 长期有效 2 相对时间生效 3 固定时间生效)  platform_coupon_validity_type 
          afterReceivingDay: '', //领取后几天生效
          effectiveDays: '', //有效天数
          dateTwo: [], //有效期时间数组，表单校验用
          validityStartTime: '', //有效期开始时间
          validityEndTime: '', //有效期截止时间
          useConditions: '1', //使用条件;(1 平台通用 2 制定行业 3 指定店铺 4 指定店铺等级)  platform_coupon_use_conditions
          couponType: '', //优惠券类型;(1 满减券 2 折扣券 3 礼品券) platform_coupon_type
          preferentialCondition: '', //优惠条件
          preferentialDiscount: '', //优惠力度
          status: '1', //是否启用;1 启用 2 禁用
          instructions: '', //使用说明
          shopTypeIdList: [], //行业类型 （二级）
          shopTypeIdLs: [], //行业类型  表单校验用
          shopIdList: [], //店铺id
          merchantCreditGradeList: [], //诚信商家等级
        },
        rules: {
          activityName: [{
            required: true,
            message: '请输入活动名称',
            trigger: ['blur', 'change']
          }, ],
          date: [{
            type: 'array',
            required: true,
            message: '请选择活动时间',
            trigger: 'change'
          }, ],
          couponStock: [{
            // required: true,
            // message: '请填写优惠券总库存数量',
            // trigger: ['blur', 'change'],
            validator: checkStock,
            trigger: ['blur', 'change'],
          }, ],
          mostEveryDay: [{
            validator: checkMostEveryDay,
            trigger: ['blur', 'change'],
          }, ],
          mostEveryPerson: [{
            validator: checkMostEveryPerson,
            trigger: ['blur', 'change'],
          }, ],
          mostEveryPersonDay: [{
            validator: checkMostEveryPersonDay,
            trigger: ['blur', 'change'],
          }, ],
          couponName: [{
            required: true,
            message: '请输入优惠券名称',
            trigger: ['blur', 'change']
          }, ],
          validityType: [{
            required: true,
            message: '请选择优惠券有效期',
            trigger: 'change'
          }],
          afterReceivingDay: [{
            validator: checkAfterReceivingDay,
            trigger: ['blur', 'change'],
          }, ],
          effectiveDays: [{
            validator: checkEffectiveDays,
            trigger: ['blur', 'change'],
          }, ],
          dateTwo: [{
            type: 'array',
            required: true,
            message: '请选择有效期',
            trigger: 'change'
          }, ],
          useConditions: [{
            required: true,
            message: '请选择使用条件',
            trigger: 'change'
          }],
          shopTypeIdLs: [{
            required: true,
            message: "请选择行业",
            trigger: ['blur', 'change'],
          }],
          shopIdList: [{
            required: true,
            message: "请选择店铺",
            trigger: ['blur', 'change'],
          }],
          merchantCreditGradeList: [{
            required: true,
            message: "请选择店铺等级",
            trigger: ['blur', 'change'],
          }],
          couponType: [{
            required: true,
            message: '请选择优惠券类型',
            trigger: 'change'
          }],
          preferentialCondition: [{
            required: true,
            validator: checkPreferentialCondition,
            trigger: ['blur', 'change'],
          }, ],
          preferentialDiscount: [{
            required: true,
            validator: checkPreferentialDiscount,
            trigger: ['blur', 'change'],
          }, ],
        }
      };
    },
    created() {
      let query = this.$route.query;
      this.type = query.type
      console.log(this.type)
      this.getSelect()
      this.getShopSelectDown()
      this.getGradeList()
      this.getCouponList()
      if (this.type == 'edit') {
        this.title = '编辑优惠券活动'
        setTimeout(() => {
          this.getCouponInfo(query.id)
        }, 100)
      }
    },
    methods: {
      
      getSelect() { //查询行业类型下拉框
        var params = {}
        shopTypeList(params).then((res) => {
          this.typeList = res.result;
          this.typeList.forEach((item) => {
            item.children.forEach((items) => {
              if (items.children.length == 0) {
                items.children = null
              }
            })
          })
        });
      },
      getShopSelectDown() { //查询店铺下拉框
        var params = {}
        shopSelectDown(params).then((res) => {
          this.shopList = res.result;
        });
      },
      getGradeList() {
        //获取商家等级
        const params = {
          dictType: "merchant_credit_grade_type",
        };
        adminDict(params).then((res) => {
          this.gradeList = res.result[0].dictList;
        });
      },
      getCouponList() {
        //获取优惠券类型
        const params = {
          dictType: "platform_coupon_type",
        };
        adminDict(params).then((res) => {
          this.couponTypeList = res.result[0].dictList;
        });
      },
      couponTypeChange(e) { //选中优惠券类型时
        console.log(e)
        this.ruleForm.preferentialDiscount = ''
      },
      getCouponInfo(id) { //获取编辑详情
        const params = {
          id: id,
        };
        couponInfo(params).then((res) => {
          this.couponStock = res.result.couponStock
          this.usableStock = res.result.usableStock
          this.platformType = res.result.platformType
          this.ruleForm = res.result
          if (res.result.useFlag == '2') {
            this.switchDisabled = true
          }
          console.log(res.result.shopTypeIdList)
          if (res.result.shopTypeIdList.length > 0) { //指定行业回显
          console.log(1111111)
            this.ruleForm.shopTypeIdLs = []
            res.result.shopTypeIdList.forEach(item => {
              var array = []
              array[0] = item.parentIndustryId
              array[1] = item.industryId
              this.ruleForm.shopTypeIdLs.push(array)
            })
          }
          this.ruleForm.couponStock = ''
          // this.ruleForm.date = []
          // this.ruleForm.date[0] = res.result.activityStartTime
          // this.ruleForm.date[1] = res.result.activityEndTime
          this.$set(this.ruleForm,'date',[res.result.activityStartTime,res.result.activityEndTime]) //用this.$set修复让回显该时间时重新选择时间页面不生效问题
          if (res.result.validityStartTime != '') {
            // this.ruleForm.dateTwo = []
            // this.ruleForm.dateTwo[0] = res.result.validityStartTime
            // this.ruleForm.dateTwo[1] = res.result.validityEndTime
            this.$set(this.ruleForm,'dateTwo',[res.result.validityStartTime,res.result.validityEndTime])
          }
        });
      },
      //制定行业选择
      changeShopTypeIdLs(e){
        console.log('e',e)
        this.ruleForm.shopTypeIdList = []
        if (this.ruleForm.shopTypeIdLs.length > 0) {
          this.ruleForm.shopTypeIdLs.forEach(item => {
            var obj = {}
            obj.parentIndustryId = item[0]
            obj.industryId = item[1]
            this.ruleForm.shopTypeIdList.push(obj)
          })
        }
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          console.log(valid)
          if (valid) {
            // this.shopTypeIdList
            this.ruleForm.activityStartTime = this.ruleForm.date[0]
            this.ruleForm.activityEndTime = this.ruleForm.date[1]
            
            if (this.ruleForm.dateTwo.length != 0) {
              this.ruleForm.validityStartTime = this.ruleForm.dateTwo[0]
              this.ruleForm.validityEndTime = this.ruleForm.dateTwo[1]
            }
            console.log('成功', this.ruleForm)
            this.submitLoading = true
            // return
            var params = {
              ...this.ruleForm,
            }
            addCoupon(params).then((res) => {
                this.$message({
                  message: "创建成功",
                  type: "success",
                });
                setTimeout(() => {
                  this.submitLoading = false
                  this.$router.push({
                    path: "/couponManagement/coupon-list",
                  });
                }, 1000);
              })
              .finally(() => {
                setTimeout(() => {
                  this.submitLoading = false;
                }, 1000)
              });
          } else {
            console.log('error submit!!', this.ruleForm);
            return false;
          }
        });
      },
      editForm(formName) { //编辑
        this.$refs[formName].validate((valid) => {
          console.log(valid)
          if (valid) {
            // this.shopTypeIdList
            this.ruleForm.activityStartTime = this.ruleForm.date[0]
            this.ruleForm.activityEndTime = this.ruleForm.date[1]
            console.log(this.ruleForm.shopTypeIdLs)
            
            // return

            // if (this.ruleForm.shopTypeIdLs != undefined && this.ruleForm.shopTypeIdLs.length > 0) {
            //   this.ruleForm.shopTypeIdList = []
            //   this.ruleForm.shopTypeIdLs.forEach(item => {
            //     var obj = {}
            //     obj.parentIndustryId = item[0]
            //     obj.industryId = item[1]
            //     this.ruleForm.shopTypeIdList.push(obj)
            //   })
            // }
            console.log(this.ruleForm.shopTypeIdList)
            if (this.ruleForm.dateTwo != undefined && this.ruleForm.dateTwo.length != 0) {
              this.ruleForm.validityStartTime = this.ruleForm.dateTwo[0]
              this.ruleForm.validityEndTime = this.ruleForm.dateTwo[1]
            }
            console.log('编辑成功', this.ruleForm)
            // return
            this.submitLoading = true
            var params = {
              ...this.ruleForm,
            }
            couponEdit(params).then((res) => {
                this.$message({
                  message: "编辑成功",
                  type: "success",
                });
                setTimeout(() => {
                  this.submitLoading = false
                  this.$router.push({
                    path: "/couponManagement/coupon-list",
                  });
                }, 1000);
              })
              .finally(() => {
                setTimeout(() => {
                  this.submitLoading = false;
                }, 1000)
              });
          } else {
            console.log('error submit!!', this.ruleForm);
            return false;
          }
        });
      },
      resetForm(formName) { //重置
        this.$refs[formName].resetFields();
      },
      clickBack() { //返回
        this.$router.push({
          path: "/couponManagement/coupon-list",
        });
      },
    }
  }

</script>
<style scoped>
  .main {
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .main_title {
    margin-bottom: 20px;
    font-weight: bold;
  }

  .lable_title {
    font-size: 14px;
    color: #606266;
    margin-right: 10px;
  }

  .lable_title_end {
    font-size: 14px;
    color: #606266;
    margin-left: 10px;
  }

  .flex {
    display: flex;
    align-items: centerf;
  }

  /* .el-input {
    width: 300px !important;
  } */

</style>
